<%@ page language="java" contentType="text/html;charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>自动生成代码系统-生成类</title>
</head>
<link href="../../../bootstrap-3.1.1-dist/css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="../../../css/pagination.css" rel="stylesheet" media="screen">
<style type="text/css">
.queryCondition{
	width: 1200px;
	float: left;
	line-height: 20px;
	margin-left: auto;
	margin-right: auto;
	padding: 5px;
	border-bottom: 1px solid #1da811;
}
.table_data{
	width: 1200px;
	float: left;
	margin-left: auto;
	margin-right: auto;	
}
.querybtn{
	text-align: center;
	border-bottom: 3px solid #1da811;
	padding-bottom: 10px;
}
.divTitle{
	width: 1200px;
	float: left;
	height: 30px;
	font-size: 18px;
	margin-left: auto;
	margin-right: auto;
	color: #999;
}
.queryCondition table tr td{
	width: 190px;
	margin: 5px 5px 5px 5px;
}
.divshow{
	width: 1200px;
	float: left;
	line-height: 20px;
	margin-left: auto;
	margin-right: auto;
	padding: 20px;
	border: 1px solid #1da811;
}
.divshowcondition{
	width: 1200px;
	float: left;
	line-height: 20px;
	margin-left: auto;
	margin-right: auto;
	padding: 20px;
}
.conditionDes{
	width: 1200px;
	float: left;
	line-height: 20px;
	margin-left: auto;
	margin-right: auto;
	color: red;
	font-size: 14px;
	text-align: center;
}
</style>
<script type="text/javascript" src="../../../js/common/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="../../../bootstrap-3.1.1-dist/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../../../js/common/jquery.pagination.js"></script>
<script type="text/javascript" src="../../../layer/layer.js"></script>
<script type="text/javascript">	
	var tableId = "";
	var tableName = "";
	$(function(){
		var args = window.location.search;
		tableId = args.split("=")[1];
		tableName = tableId.split("-")[3];
		$.ajax({
			type : 'post',
			dataType: 'json',
			contentType: "application/json",
			async: false, 
		    url: '../../stf.do?action=0&tableId=' + tableId,
		    success: function(data) {
		    	var chkhtml = "<table>";
		    	$.each(data.rows, function(i,v){
		    		if(i == 0){
		    			chkhtml += htmlCheckBoxStart(v.fieldEnglishName, v.fieldType);
		    		}else{		    		
			    		if(i % 6 == 0){
			    			chkhtml += htmlCheckBoxTr(v.fieldEnglishName, v.fieldType);
			    		}
			    		
			    		if(i % 6 != 0){
			    			chkhtml += htmlCheckBox(v.fieldEnglishName, v.fieldType);
			    		}
		    		}
		    		
		    	
		    	});
		    	
		    	chkhtml += "</table>";
		    	
		    	$("#divChks").html(chkhtml);
		    	$("#divChks1").html(chkhtml);
				
		    }  
		}); 
	});

	function htmlCheckBoxStart(fieldName, fieldType){
		var html = "";
		html += "<tr><td><input type=\"checkbox\" value=\"" + fieldName + "\"/><span>" + fieldName + "</span><span style=\"display:none;\">" + fieldType + "</span></td>";
		return html;
	}
	
	function htmlCheckBox(fieldName, fieldType){
		var html = "";
		html += "<td><input type=\"checkbox\" value=\"" + fieldName + "\"/><span>" + fieldName + "</span><span style=\"display:none;\">" + fieldType + "</span></td>";
		return html;
	}
	function htmlCheckBoxTr(fieldName, fieldType){
		var html = "";
		html += "</tr><tr><td><input type=\"checkbox\" value=\"" + fieldName + "\"/><span>" + fieldName + "</span><span style=\"display:none;\">" + fieldType + "</span></td>";
		return html;
	}
	
	
	function btnReturn(){
		window.location.href = "/meileche/admin/sql/design.jsp?tableId="+tableId;
	}
	
	function btnCondition(){
		var trObj = $("#divChks1 table tr");
		var trLength = $("#divChks1 table tr").length;
		var condition = "where ";
		for(var i = 0; i< trLength;i++){
			var tdObj = trObj.eq(i).find("td");
			var tdLength = tdObj.length;
			for(var j = 0; j< tdLength;j++){
				var inputObj = tdObj.eq(j).find("input");
				
				if(inputObj.attr("checked")== "checked"){
					condition += inputObj.val() + "='123456789' and ";
				}
			}
		}
		
		if(condition != "where "){
			condition = condition.substring(0, condition.length - 4);
			$("#txtCondition").val(condition);			
		}
	}
	
	function btnClearSql(){
		$("#divShow").html('');
	}
	function clearTxt(){
		$("#txtCondition").val('');
	}
	function btnidao(){
		
		$.layer({
			shade : [0.5 , '#000' , true],
			type : 1,
			area : ['600','200'],
			title : false,
			border : [0],
			page : {dom : '#hidClassPathAndPackage'},
			close : function(index){
				layer.close(index);
				$('#hidClassPathAndPackage').hide();
			}
		});
		
	}
	
	function btnGenerateClass(){
		var path = $("#txtPath").val();
		if(path == ""){
			$("#divPathPackageWarn").html("类项目路径不能为空");
			return;
		}
		
		var packages = $("#txtPackage").val();		
		if(packages == ""){
			$("#divPathPackageWarn").html("类包名不能为空");
			return;
		}
		var data = new Object();
		data.path = path;
		data.packages = packages;
		var json = JSON.stringify(data);
		$.ajax({
			type : 'post',
			contentType: "application/json",
			data: json,
		    url: '../../stf.do?action=5&tableId=' + tableId,
		    success: function(v) {
		    	$("#txtPath").val('');
		    	$("#txtPackage").val('');
		    }  
		});
	}
	
	window.onload = function() {
		$('.selectpicker').selectpicker();
	};
	
</script>
<body>
	<div style="width:1200px;margin-left:auto;margin-right:auto;">
		<div class="querybtn">
			<input type="hidden" value="0" id="hidTableNameValue"/>
			
			<input type="button"  class="btn btn-success" style="width:100px;margin-right: 10px;" value="返回" onclick="btnReturn();"/>
			<input type="button"  class="btn btn-success" style="width:100px;margin-right: 10px;" value="生成条件" onclick="btnCondition();"/>
			<input type="button" class="btn btn-success" style="width:100px;margin-right: 10px;"  value="清除条件" onclick="clearTxt();"/>
			<input type="button"  class="btn btn-primary" style="width:100px;margin-right: 10px;" value="生成IDAO" onclick="btnidao();"/>
			<input type="button"  class="btn btn-primary" style="width:100px;margin-right: 10px;" value="生成Select" onclick="btnImport();"/>
			<input type="button"  class="btn btn-primary" style="width:100px;margin-right: 10px;" value="生成Delete" onclick="btnImport();"/>
			<input type="button"  class="btn btn-primary" style="width:100px;margin-right: 10px;" value="生成Update" onclick="btnImport();"/>
			<input type="button"  class="btn btn-primary" style="width:100px;margin-right: 10px;" value="清除SQL" onclick="btnClearSql();"/>
		</div>
		
		<div class="querybtn">	
			<select class="selectpicker span2" data-size="false">
				<option>-IDAO方法-</option>
				<option>-DAO方法-</option>
				<option>-Bussiness方法-</option>
			</select>		
			<input type="checkbox"  value="添加方法" id="chkAdd"/>添加方法&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<input type="checkbox"  value="删除方法" />删除方法&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<input type="checkbox" value="更新方法" />更新方法&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<input type="checkbox"  value="修改方法"/>修改方法&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<input type="checkbox" value="分页方法"/>分页方法&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<input type="checkbox" value="求总条数方法"/>求总条数方法&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		</div>
		<div class="divTitle">
			条件编辑区域
		</div>
		<div class="conditionDes">
			备注：Insert语句没有条件
		</div>
		<div class="divshowcondition">
			<textarea style="width:100%;height:100px;" id="txtCondition"></textarea>
		</div>
		<div class="divTitle">
			字段&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" value="0"/><span style="color:#1da811;">全选</span>
		</div>
		<div class="queryCondition" id="divChks">
			
		</div>
		<div class="divTitle" >
			条件&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" value="0"/><span style="color:#1da811;">全选</span>
		</div>
		<div class="queryCondition" id="divChks1">
			
		</div>
		<div class="divTitle" >
			SQL语句
		</div>
		<div class="divshow" id="divShow">
			
		</div>
		<div style="display:none;color: #444;text-align:center;float:left;align:center;" id="hidClassPathAndPackage">
			<table>
				<tr>
					<td><span style="margin:5px 5px 5px 5px;">类项目路径</span></td>
					<td><input type="text" id="txtPath" style="width:500px;margin:5px 5px 5px 5px;height: 30px;"/></td>
				</tr>
				<tr>
					<td><span style="margin:5px 5px 5px 5px;">类包名</span></td>
					<td><input type="text" id="txtPackage" style="width:500px;margin:5px 5px 5px 5px;height: 30px;"/></td>
				
				</tr>
				<tr>
					<td colspan="2"><input type="button" value="生成" style="width: 200px;margin:5px 5px 5px 5px;" class="btn btn-primary" onclick="btnGenerateClass();"/></td>
				</tr>
			</table>
			<div style="width:100%;border:1px #ccc solid;height: 80px;color: #FF4040;" id="divPathPackageWarn">
			
			</div>
		</div>
	</div>
</body>
</html>